package com.example.oasystem.dao.address;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.oasystem.entity.address.AoaDirector;
import com.example.oasystem.entity.address.OutShowDTO;
import com.example.oasystem.entity.daymanage.EmpDTO;
import com.example.oasystem.entity.user.AoaUser;
import org.apache.catalina.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AoaDirectorDao extends BaseMapper<AoaDirectorDao> {

    //获取内部通讯录
    List<AoaUser> getIndoorUser(@Param("text") String text, @Param("baseKey")String baseKey);
    //获取外部通讯录菜单
    List<String> getCate(Long userId);
    @Select( "select count(*) from aoa_director_users d where d.user_id = #{id}  and d.share_user_id is not null AND d.is_handle=0")
    int selectNoHandle(Long id);
    List<EmpDTO> getAllEmps(@Param("text") String text,Long userid);
    //获取外部通讯录
    List<AoaDirector> getOutUser(@Param("userId") int userId, @Param("text")String text, @Param("outtype")String outtype,@Param("baseKey")String baseKey);

    //查看内部通讯录
    AoaUser findIn(int userId);
    //查看外部通讯录
    OutShowDTO findOut(int directorId);
    //修改外部通讯录名称
    @Update("update aoa_director_users set catelog_name = #{typeName} where catelog_name = #{oldTypeName} and user_id = #{userId}")
    Integer updateOutTypeName(String oldTypeName,String typeName, Long  userId);
    //新增外部通讯录分类
    @Insert("insert into aoa_director_users(catelog_name,is_handle,user_id) values(#{typeName},0,#{userId})")
    Integer AddOutTypeName(Long userId,String typeName);
    //删除外部通讯录分类
    @Delete("delete from aoa_director_users where catelog_name = #{typeName} and user_id = #{userId}")
    Integer deleteOutTypeName(Long userId,String typeName);

    //我共享的
    List<AoaDirector> getMeShareMess(@Param("userId") Long userId,@Param("text") String text);
    //接受共享
    Integer updateShareMess(@Param("catalog")String catalog,@Param("directorUsersId")int directorUsersId);
    //共享与我
    List<AoaDirector> getShareMeMess(@Param("userId") Long userId,@Param("text") String text);

    //通过directorId查找director对象
    AoaDirector findDirector(int did);

    //插入director主表是数据
    Integer addDirector(AoaDirector director);

    //插入directoruser表数据
    @Insert("insert into aoa_director_users(is_handle,director_id,user_id,catelog_name) values(1,#{directorId},#{userId},#{catalogName})")
    Integer addDirectorUser(Long directorId,Long userId,String catalogName);

    Integer updateDirectorUser(AoaDirector director,Long did);

    @Update("update aoa_director_users set catelog_name = #{catelogName} where user_id = #{userId} and director_id = #{directorId}")
    Integer updateDirector(String catelogName,Long userId,Long directorId);


    @Select("select image_path from aoa_director where director_id=#{id}")
    int selectPathId(Long id);

    //分享验证重复
    @Select("select count(*) from aoa_director_users where director_id = #{directorId} and (user_id = #{shareId} or share_user_id = #{shareId})")
    Integer checkShare(int directorId,int shareId);

    @Insert("insert into aoa_director_users(is_handle,director_id,user_id,share_user_id,sharetime) values(0,#{directorId},#{shareId},#{userId},#{date}) ")
    Integer shareUser(int shareId,int userId,int directorId,String date);

    EmpDTO getEmpsById(int userId);

    @Delete("delete from aoa_director_users where director_users_id = #{did}")
    Integer deletedirectorUser(int did);
}